#include "eveCommon.h"
#include "eveGuiStatic.h"
#include "eveTheme.h"

CGuiStatic::CGuiStatic(CGuiControl* parent,const String& type) 
: CGuiControl(parent,type)
, m_strText()
, m_font(0)
, m_dwColor(0xffffffff)
, m_align(0)
{

}

CGuiStatic::~CGuiStatic()
{
}

void CGuiStatic::Create(CGuiElementHolder* holder,uint32 id,uint32 style)
{
	//const CGuiElementHolder* eleholder = theme->GetElementsByCtrlName(m_type);
	CGuiControl::Create(holder,id,style);
	m_pCtrlRender = new CGuiStaticRender(*this,holder);
}
void CGuiStatic::ParseExtendProperty(TiXmlElement* element)
{
	if( !element ) return;
	XMLElementWrapper wrapper(element);	
		const String& name = wrapper.GetStringValue("name");
		if( name == "font" )
		{
			m_font = StringUtil::ToInt(wrapper.GetNodeText());
		}
		else if( name == "color" )
		{
			m_dwColor = StringUtil::ToColor(wrapper.GetNodeText());
		}
		else if( name == "text" )
		{
			m_strText = wrapper.GetNodeText();
		}
		else if( name == "align" )
		{
			m_align = StringUtil::ToInt(wrapper.GetNodeText());
		}
		
	
}
void CGuiStaticRender::Render(Real timeDelta)
{
	const stRectI & oldrc = RenderSystem::GetSingleton()->SetClipRect(m_rControl.GetClientRect());
	
	for( vector<CGuiElementInstance*>::iterator iter = m_elementinstances.begin(); 
	 iter != m_elementinstances.end(); ++iter )
	{
		CGuiElementInstance* instance = (*iter);
		if( instance )
		{
			instance->Render(&m_rControl,
				m_rControl.GetClientRect(),
				m_rControl.m_strText,
				m_rControl.m_font,
				m_rControl.m_dwColor,m_rControl.m_align,
				timeDelta);
		}
	}
	RenderSystem::GetSingleton()->SetClipRect(oldrc);
}	